<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>岗位ID：</label>
                                <input type="text" name="postId"/>
                            </li>
                            <li>
                                <label>时间：</label>
                                <input type="text" class="time-input" placeholder="请选择时间" name="freeTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wstudy:apply:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wstudy:apply:remove')}]];
        var statusDatas = [[${@dict.getType('wst_apply_status')}]];
        var prefix = ctx + "wstudy/apply";
        var prefixPro = ctx + "wstudy/process";

        $(function() {
            var options = {
                url: prefix + "/list/student",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "申请",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'applyId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'postId',
                    title: '岗位ID',
                    visible: false
                },
                {
                    field: 'studentId',
                    title: '学生ID',
                    visible: false
                },
                {
                    field: 'freeId',
                    title: '时间ID',
                    visible: false
                },
                {
                    field: 'post.postName',
                    title: '岗位名称'
                },
                {
                    field: 'experience',
                    title: '经验'
                },
                {
                    field: 'evaluate',
                    title: '自我评价'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'createUserId',
                    title: '创建者ID',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'applyStatus',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        let applyStatus= "WAITING_FOR_APPROVAL" == row.status;
                        let successSta= "APPROVAL_SUCCESS" == row.status;
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="details(\'' + row.applyId +'\',\''+row.post.createUserId+ '\')"><i class="fa fa-search"></i>详情</a> ');
                        if (applyStatus){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="revokeApply(\'' + row.applyId +'\',\''+row.post.createUserId+ '\')"><i class="fa fa-remove"></i>撤销</a>');
                        }
                        if (successSta){
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="agree(\'' + row.applyId + '\',\''+row.postId + '\',\''+row.post.createUserId+'\')"><i class="fa fa-check"></i>应聘</a>');
                            actions.push(' <a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="disAgree(\'' + row.applyId + '\',\''+row.postId+ '\',\''+row.post.createUserId+'\')"><i class="fa fa-remove"></i>拒绝</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function details(id) {
            $.modal.openTab("详情",prefix+"/details/"+id);
        }
        function agree(applyId,postId,receiveUserId) {
            let params={
                "applyId":applyId,
                "postId":postId,
                "params[status]":"AGREE"
            }
            let params2 = {
                "receiveUserId":receiveUserId,
                "status":"no",
                "content":"消息内容：有学生应聘岗位！",
                "type":"消息提醒"
            }
            $.modal.confirm("确定同意此次申请吗？",function () {
                $.operate.save(prefixPro+"/offer",params,function () {
                    $.operate.post( "/wstudy/message/send",params2)
                });
            })
        }
        //拒绝应聘
        function disAgree(applyId,postId,receiveUserId){
            let params={
                "applyId":applyId,
                "postId":postId,
                "params[status]":"DISAGREE"
            }
            let params2 = {
                "receiveUserId":receiveUserId,
                "status":"no",
                "content":"消息内容：有学生取消应聘岗位！",
                "type":"消息提醒"
            }
            $.modal.confirm("确定取消此次申请吗？",function () {
                $.operate.save(prefixPro+"/offer",params,function () {
                    $.operate.post( "/wstudy/message/send",params2)
                });
            })
        }
        //撤销
        function revokeApply(applyId,receiveUserId) {
            let params = {
                "receiveUserId":receiveUserId,
                "status":"no",
                "content":"消息内容：有学生撤销岗位申请！",
                "type":"消息提醒"
            }
            $.modal.confirm("确定撤销此次申请吗？",function () {
                $.operate.post(prefix+"/remove",{"ids":applyId},function () {
                    if (arguments[0].code==0){
                        $.operate.post( "/wstudy/message/send",params)
                    }
                });
            });
        }
    </script>
</body>
</html>